<template>
  <!-- 申请加入设置组件 -->
  <div class="vy-cmp-cs-join-settings">
    <div class="vy-cmp-common-title">
      <span class="vy-cmp-common-title-left">申请加入设置</span>
    </div>
    <div class="vy-cmp-cs-join-settings-container">
      <div class="vy-cmp-cs-join-settings-form">
        <a-form>
          <a-form-item label="项目类型" :colon="false" v-bind="formItemLayout">
            <a-radio-group v-model="formData.openState">
              <a-radio :value="1">私密</a-radio>
              <a-radio :value="0">公开</a-radio>
            </a-radio-group>
          </a-form-item>
          <template>
            <a-form-item
              label=" "
              :colon="false"
              v-bind="formItemLayout"
              extra="开启后，不在通讯录的成员申请加入，须管理员审核通过才能加入项目  "
            >
              <a-checkbox
                :checked="!!formData.isCheck"
                @change="click_change_checkbox('isCheck', $event)"
              >
                需管理员审核
              </a-checkbox>
            </a-form-item>
            <a-form-item
              label=" "
              :colon="false"
              v-bind="formItemLayout"
              extra="开启后，成员在提交加入申请时，需按提示填写备注  "
            >
              <a-checkbox
                :checked="!!formData.isApply"
                @change="click_change_checkbox('isApply', $event)"
              >
                报名字段
              </a-checkbox>
            </a-form-item>
          </template>

          <a-form-item>
            <a-button type="primary" @click="click_save_info"
              >保存更改</a-button
            >
          </a-form-item>
        </a-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "vy-cmp-cs-join-settings",
  data() {
    return {
      formItemLayout: {
        labelCol: {
          span: 4
        },
        wrapperCol: {
          span: 20
        }
      },
      projectId: null, // 项目id
      // 表单字段数据
      formData: {
        openState: 1, // 开放状态, 0: 公开, 1: 私密
        isCheck: 0, // 需管理员审核,0:否,1:是; 若openState为0(公开),则不展示”需管理员审核”以及”报名字段”两项内容
        isApply: 0 // 报名字段,加入项目是否需要申请,0:否,1:是
      }
    };
  },
  created() {
    this.projectId = this.$route.query.projectId;
  },
  mounted() {
    this.$nextTick(() => {
      this.queryInfo();
    });
  },
  methods: {
    // 查询该项目申请加入设置
    queryInfo() {
      let params = {
        projectId: this.projectId
      };
      this.$axios
        .get("/projectSetting/getApplySetting", { params })
        .then(res => {
          this.formData.openState = res.openState;
          this.formData.isCheck = res.isCheck;
          this.formData.isApply = res.isApply;
        });
    },
    // 更新项目申请加入设置
    saveInfo() {
      let params = Object.assign(
        {
          id: this.projectId
        },
        this.formData
      );
      this.$axios
        .post("/projectSetting/updateApplySetting", params)
        .then(res => {
          if (res.success) {
            this.$message.success(res.msg);
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    // checkbox change事件
    click_change_checkbox(field, e) {
      this.formData[field] = e.target.checked ? 1 : 0;
    },
    // 保存更改
    click_save_info() {
      this.saveInfo();
    }
  }
};
</script>

<style type="text/css" lang="scss">
.vy-cmp-cs-join-settings {
  width: 100%;
  height: 100%;
  background: #ffffff;
  .ant-form-item {
    border-bottom: 1px solid rgba(235, 235, 236, 1);
    padding: 12px 0;
    margin-bottom: 0;
    &:last-child,
    &:nth-last-child(2) {
      border: none;
    }
    .ant-form-item-label {
      text-align: left;
    }
  }
  .ant-radio-wrapper {
    width: 100%;
  }
}
</style>
